/**
 * @Date: Mar 3, 2010 1:56:32 PM
 */
package com.philip.journal.home.dao;

import java.util.List;
import java.util.Map;

import com.philip.journal.core.exception.JournalException;
import com.philip.journal.home.bean.Entry;

/**
 * @author cry30
 */
public interface EntryDAO {

    /**
     * Retrieves all Entry under the given branch Id.
     *
     * @param branchId ID of branch whose children are to be retrieved.
     * @return Branches under the given branch id.
     */
    List<Entry> readAllByBranch(long branchId);

    /**
     * Persist the given Entry into the DB. Insert will be performed if the entryId is not set, other wise update.
     *
     * @param entry the Entry entity object to persist.
     * @exception JournalException If any of the following is true: *
     *                <ul>
     *                <li><code>object</code>passed has a non-existent primary key value.
     *                <li>Duplicate title under the same branch.
     *                </ul>
     * @exception IllegalArgumentException when entry passed is null.
     */
    void save(Entry entry);

    /**
     * Deletes the record given the entryId.
     *
     * @param entryId the id of the entry to delete.
     *
     * @exception JournalException when no record exist with the given entryId.
     */
    void delete(long entryId);

    /**
     * Delete all records.
     * 
     * @param entries List of Entry's to delete.
     * @exception JournalException when an entry is not found in the data store.
     */
    void deleteAll(List<Entry> entries);

    /**
     * @param entryId id of the Entry to read from data source.
     * @return null if the the specified Entry id did not match any record, otherwise returns the corresponding Entry
     *         object.
     */
    Entry read(long entryId);

    /**
     * Reads an Entry matching the title in the given branch id. This is used to pre determine if an insert will be
     * successful or not if a constraint is enforced in the database.
     *
     * @param title name/title to match.
     * @param branchId branch id from where to search the title/name.
     * @return null if the the specified title and branch id is not present, otherwise returns the corresponding Entry
     *         object.
     */
    Entry readByTitle(String title, long branchId);

    /**
     * Searches for all Entry object matching (LIKE case insensitive) all the specified criteria.
     *
     * @param criteria mapping of property to value to match.
     * @return List of Entry satisfying the list of criteria.
     */
    List<Entry> searchIlike(Map<String, String> criteria);

}

